package com.zygk.locationtool.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.zygk.locationtool.R;
import com.zygk.locationtool.model.M_Project;
import com.zygk.library.adapter.BaseListAdapter;
import java.util.List;

/**
 * 首页项目列表
 */
public class HomeProjectAdapter extends BaseListAdapter<M_Project> {

  public HomeProjectAdapter(Context context, List<M_Project> list) {
    super(context, list);
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder holder = null;
    if (convertView == null) {
      convertView = mInflater.inflate(R.layout.item_home_project, null, false);
      holder = new ViewHolder(convertView);

      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    final M_Project entity = getItem(position);
    holder.tvName.setText(entity.getProjectName());
    mImageManager.loadUrlImage(entity.getLogoImageUrl(), holder.ivIcon);

    return convertView;
  }

  static class ViewHolder {
    @BindView(R.id.iv_icon) ImageView ivIcon;
    @BindView(R.id.tv_name) TextView tvName;

    ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }
}
